function selected() {
	var selectedCategory = "";
	$("#unselectedCategory").find("tr").each(function() {
		var tdArr = $(this).children();
		var input = tdArr.eq(0).find("input");
		if ($(input).get(0).checked) {
			var classifyNo = tdArr.eq(0).next().text();
			selectedCategory += "<tr>" + $(this).html() + "</tr>";
			$(this).remove();
		}
	});
	$("#selectedCategory").append(selectedCategory);
	$("#record_count").html("合计共 " + parseInt($("#unselectedCategory").find("tr").length-1) + " 条记录");
	$("#record_count_").html("合计共 " + parseInt($("#selectedCategory").find("tr").length-1) + " 条记录");
}

function unselected() {
	var unselectedCategory = "";
	// 获取选中的器械编号
	$("#selectedCategory").find("tr").each(function() {
		var tdArr = $(this).children();
		var input = tdArr.eq(0).find("input");
		if ($(input).get(0).checked) {
			var classifyNo = tdArr.eq(0).next().text();
			unselectedCategory += "<tr>" + $(this).html() + "</tr>";
			$(this).remove();
		}
	});
	$("#unselectedCategory").append(unselectedCategory);
	$("#record_count").html("合计共 " + parseInt( $("#unselectedCategory").find("tr").length-1) + " 条记录");
	$("#record_count_").html("合计共 " + parseInt($("#selectedCategory").find("tr").length-1) + " 条记录");
}

// 经营范围保存
function saveBusinessScope() {
	// 存放器械分类编号的数组
	var selectedContent = "";
	// 获取选中的器械编号
	var i = 0;
	$("#selectedCategory").find("tr").each(function() {
		if (i != 0) {
			var tdArr = $(this).children();
			selectedContent += $(this).text() + ";";
		}
		i++;

	});
	$("#business_scope").val(Trim(selectedContent, "g"));
	$("#setting").modal("hide");
}

//去掉所有空格
function Trim(str, is_global) {
	var result;
	result = str.replace(/(^\s+)|(\s+$)/g, "");
	if (is_global.toLowerCase() == "g") {
		result = result.replace(/\s/g, "");
	}
	return result;
}



var text = "";
// 模糊查询
// 实时筛选，不用点击按钮
$("#searchContent").keyup(
		function() {
			text = $("#searchContent").val();// 获取文本框输入
			if ($.trim(text) != "") {
				$("#unselectedCategory tr:not('#theader')").hide().filter(
						":contains('" + text + "')").show();
			} else {
				$("#unselectedCategory tr").show();// 当删除文本框的内容时，又重新显示表格所有内容
			}
		});

$("#searchContent_").keyup(
		function() {
			text = $("#searchContent_").val();// 获取文本框输入
			if ($.trim(text) != "") {
				$("#selectedCategory tr:not('#theader_')").hide().filter(
						":contains('" + text + "')").show();
			} else {
				$("#selectedCategory tr").show();// 当删除文本框的内容时，又重新显示表格所有内容
			}
		});


//设置企业经营范围
settings = function () {
	if ($("#selectSupplierNo").val() == "") {
		layer.msg('请先选择供应商!', {
			icon : 5,
			time : 1000
		});
		$("#set").removeAttr("data-target");
		return;
	}
	$("#set").attr("data-target", "#setting");
	$
			.ajax({
				type : "post",
				url : "/Medical_Instrument/enterpriseInstrument/getInstrumentBySupplierNo",
				data : {
					supplier_enterprise_no : $("#selectSupplierNo")
							.val()
				},
				dataType : "json",
				success : function(data) {
					if (data != null) {
						$("#unselectedCategory").html("");
						var content = "<tr id='theader'><td><input type='checkbox' /></td>"
								+ "<td>分类编号</td>"
								+ "<td>代码编号</td>"
								+ "<td>分类代码</td>"
								+ "<td>管理类别</td></tr>";

						for ( var i = 0; i < data.length; i++) {
							content += "<tr><td><input type='checkbox'/></td>"
									+ "<td>"
									+ data[i].classifyNo
									+ "</td>"
									+ "<td>"
									+ data[i].codeNo
									+ "</td>"
									+ "<td>"
									+ data[i].classifyName
									+ "</td>"
									+ "<td>"
									+ data[i].manageType
									+ "</td></tr>";
						}

						$("#unselectedCategory").html(content);
						$("#record_count").html(
								"合计共 " + data.length + " 条记录");
					}
					;
				},
				error : function(data) {
					layer.msg('请求失败!', {
						icon : 5,
						time : 1000
					});
				}
			});

}

